package app.qrcode.browser.hearttoheart.adapters

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import app.qrcode.browser.hearttoheart.R

/**
 * Created by DomenCai on 2022/3/31.
 */
class SettingsImageAdapter : RecyclerView.Adapter<SettingsImageAdapter.SettingsImageViewHolder>() {

    private val settingsList: MutableList<SettingsImage> = mutableListOf()

    @SuppressLint("NotifyDataSetChanged")
    fun updateList(newList: ArrayList<SettingsImage>) {
        settingsList.clear()
        settingsList.addAll(newList)
        notifyDataSetChanged()
    }

    inner class SettingsImageViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val settingText: TextView = view.findViewById(R.id.settting_TV)
        val settingsImage: ImageView = view.findViewById(R.id.setting_image)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SettingsImageViewHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.item_setttings, parent, false)
        return SettingsImageViewHolder(view)
    }

    override fun onBindViewHolder(holder: SettingsImageViewHolder, position: Int) {
        val setting = settingsList[position]
        holder.settingText.text = setting.settingText
        holder.settingsImage.setImageResource(setting.settingPic)
    }

    override fun getItemCount(): Int = settingsList.size
}